import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }

    public boolean wordPattern(String pattern, String s) {
        HashMap<Character,String> map1 = new HashMap<>();
        HashMap<String,Character> map2 = new HashMap<>();

        String[] words = s.split(" ");
        if (pattern.length() != words.length) {
            return false; // 如果pattern和words的长度不相等，直接返回false
        }
        for(int i=0;i<pattern.length();i++) {
            if(map1.containsKey(pattern.charAt(i))){
                if(!map1.get(pattern.charAt(i)).equals(words[i]))return false;
            }else{
                map1.put(pattern.charAt(i),words[i]);
            }

            if(map2.containsKey(words[i])){
                if(!map2.get(words[i]).equals(pattern.charAt(i))){
                    return false;
                }
            }else{
                map2.put(words[i],pattern.charAt(i));
            }
        }
        return true;
    }

    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        if(s.length()==0)return false;
        for(int i=0;i<s.length();i++){
            char c = s.charAt(i);
            if(c=='('||c=='{'||c=='['){
                stack.push(c);
            }else{
                if(stack.isEmpty()){
                    return false;
                }
                if(stack.peek()=='('&&c==')'||stack.peek()=='{'&&c=='}'||stack.peek()=='['&&c==']'){
                    stack.pop();
                }else{
                    return false;
                }
            }
        }
        return stack.isEmpty()?true:false;
    }
}